package com.shd.edanpei.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseQuickImageAdapter;
import com.shd.edanpei.bean.PlanLineBean;

import java.util.List;

/**
 * Created by mc on 2018/9/21.
 * yang-wen-wen
 */

public class PlanLineAdapter extends BaseQuickImageAdapter<PlanLineBean> {

    View lineLeft, lineRight;
    ImageView point;
    private List<PlanLineBean> lists;

    public PlanLineAdapter(Context context) {
        super(context, R.layout.item_plan_line);
    }


    @Override
    protected void convert(BaseViewHolder helper, PlanLineBean item) {
        helper.setText(R.id.status, item.getStatus());
        int position = helper.getLayoutPosition();
        lists = getData();
        lineLeft = helper.getView(R.id.line_left);
        lineRight = helper.getView(R.id.line_right);
        point = helper.getView(R.id.point);

        //第一项和最后一项 隐藏左右line
        if (position == 0) {
            lineLeft.setVisibility(View.INVISIBLE);
        } else if (position == lists.size() - 1) {
            lineRight.setVisibility(View.INVISIBLE);
        }
        //设置point
        if (item.isTag()) {
            if (position == lists.size() - 1) {
                point.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.point_blue_big));
            } else {
                point.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.point_blue_small));
            }
        } else {
            if (position == lists.size() - 1) {
                point.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.point_gray_big));
            } else {
                point.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.point_gray_small));
            }
        }
        //设置左线颜色
        if (item.isTag()) {
            lineLeft.setBackground(ContextCompat.getDrawable(mContext, R.drawable.line_blue));
        } else {
            lineLeft.setBackground(ContextCompat.getDrawable(mContext, R.drawable.line_gray));
        }
        //设置右线颜色，因为右线是根据下一项状态来改变的，所以这里取下一项状态进行判断,最后一项不需判断
        if (position != lists.size() - 1) {
            if (lists.get(position + 1).isTag()) {
                lineRight.setBackground(ContextCompat.getDrawable(mContext, R.drawable.line_blue));
            } else {
                lineRight.setBackground(ContextCompat.getDrawable(mContext, R.drawable.line_gray));
            }
        }
    }


}